home *** CD-ROM | disk | FTP | other *** search
/ Champak 54 / Vol 54.iso / games / for_birt.swf / scripts / __Packages / mx / controls / ProgressBar.as next >
Encoding:
Text File  |  2007-09-27  |  18.9 KB  |  627 lines

  1. class mx.controls.ProgressBar extends mx.core.UIObject
  2. {
  3.    var boundingBox_mc;
  4.    var progTrackLeft_mc;
  5.    var progTrackMiddle_mc;
  6.    var progTrackRight_mc;
  7.    var progBarLeft_mc;
  8.    var progBarMiddle_mc;
  9.    var progBarRight_mc;
  10.    var progIndBar_mc;
  11.    var mask_mc;
  12.    var labelPath;
  13.    var __width;
  14.    var __height;
  15.    var __source;
  16.    var __stringSource;
  17.    var si;
  18.    var dispatchEvent;
  19.    static var symbolName = "ProgressBar";
  20.    static var symbolOwner = Object(mx.controls.ProgressBar);
  21.    var className = "ProgressBar";
  22.    static var version = "2.0.0.360";
  23.    var __mode = "event";
  24.    var __direction = "right";
  25.    var __labelPlacement = "bottom";
  26.    var __label = "LOADING %3%% ";
  27.    var __conversion = 1;
  28.    var __maximum = 0;
  29.    var __minimum = 0;
  30.    var __value = 0;
  31.    var __indeterminate = false;
  32.    var progTrackLeftName = "ProgTrackLeft";
  33.    var progTrackMiddleName = "ProgTrackMiddle";
  34.    var progTrackRightName = "ProgTrackRight";
  35.    var progBarLeftName = "ProgBarLeft";
  36.    var progBarMiddleName = "ProgBarMiddle";
  37.    var progBarRightName = "ProgBarRight";
  38.    var progIndBarName = "ProgIndBar";
  39.    var idNames = new Array("progTrackLeft_mc","progTrackMiddle_mc","progTrackRight_mc","progBarLeft_mc","progBarMiddle_mc","progBarRight_mc","progIndBar_mc");
  40.    var skinIDProgTrackLeft = 0;
  41.    var skinIDProgTrackMiddle = 1;
  42.    var skinIDProgTrackRight = 2;
  43.    var skinIDProgBarLeft = 3;
  44.    var skinIDProgBarMiddle = 4;
  45.    var skinIDProgBarRight = 5;
  46.    var skinIDProgIndBar = 6;
  47.    var skinIDMask = 100;
  48.    var skinIDLabel = 200;
  49.    var __interval = 30;
  50.    var __leave = 2;
  51.    var clipParameters = {mode:1,source:1,direction:1,label:1,labelPlacement:1,conversion:1};
  52.    static var mergedClipParameters = mx.core.UIObject.mergeClipParameters(mx.controls.ProgressBar.prototype.clipParameters,mx.core.UIObject.prototype.clipParameters);
  53.    function ProgressBar()
  54.    {
  55.       super();
  56.    }
  57.    function init(Void)
  58.    {
  59.       super.init();
  60.       this.tabEnabled = false;
  61.       this.boundingBox_mc._visible = false;
  62.       this.boundingBox_mc._width = this.boundingBox_mc._height = 0;
  63.    }
  64.    function createChildren(Void)
  65.    {
  66.       if(this.progTrackLeft_mc == undefined)
  67.       {
  68.          this.setSkin(this.skinIDProgTrackLeft,this.progTrackLeftName);
  69.       }
  70.       if(this.progTrackMiddle_mc == undefined)
  71.       {
  72.          this.setSkin(this.skinIDProgTrackMiddle,this.progTrackMiddleName);
  73.       }
  74.       if(this.progTrackRight_mc == undefined)
  75.       {
  76.          this.setSkin(this.skinIDProgTrackRight,this.progTrackRightName);
  77.       }
  78.       if(this.progBarLeft_mc == undefined)
  79.       {
  80.          this.setSkin(this.skinIDProgBarLeft,this.progBarLeftName);
  81.       }
  82.       if(this.progBarMiddle_mc == undefined)
  83.       {
  84.          this.setSkin(this.skinIDProgBarMiddle,this.progBarMiddleName);
  85.       }
  86.       if(this.progBarRight_mc == undefined)
  87.       {
  88.          this.setSkin(this.skinIDProgBarRight,this.progBarRightName);
  89.       }
  90.       if(this.progIndBar_mc == undefined)
  91.       {
  92.          this.setSkin(this.skinIDProgIndBar,this.progIndBarName);
  93.          this.progIndBar_mc._visible = false;
  94.       }
  95.       if(this.mask_mc == undefined)
  96.       {
  97.          this.mask_mc = this.createObject("BoundingBox","mask_mc",this.skinIDMask);
  98.          this.mask_mc._visible = false;
  99.          this.progIndBar_mc.setMask(this.mask_mc);
  100.       }
  101.       if(this.labelPath == undefined)
  102.       {
  103.          this.labelPath = this.createLabel("labelPath",this.skinIDLabel);
  104.          this.labelPath.tabEnabled = false;
  105.          this.labelPath.selectable = false;
  106.          this.labelPath.styleName = this;
  107.       }
  108.       this.setSize(this.__width,this.__height);
  109.    }
  110.    function size(Void)
  111.    {
  112.       this.invalidate();
  113.    }
  114.    function draw(Void)
  115.    {
  116.       if(this.__source == undefined && this.__stringSource != undefined)
  117.       {
  118.          this.setSource(this.__stringSource);
  119.          this.__stringSource = undefined;
  120.       }
  121.       var _loc14_ = this.__width;
  122.       var _loc22_ = this.__height;
  123.       var _loc5_ = this.progBarLeft_mc._width <= this.progTrackLeft_mc._width ? this.progTrackLeft_mc._width : this.progBarLeft_mc._width;
  124.       var _loc6_ = this.progBarLeft_mc._height <= this.progTrackLeft_mc._height ? this.progTrackLeft_mc._height : this.progBarLeft_mc._height;
  125.       var _loc15_ = this.progBarRight_mc._width <= this.progTrackRight_mc._width ? this.progTrackRight_mc._width : this.progBarRight_mc._width;
  126.       var _loc7_ = _loc14_;
  127.       var _loc8_ = 0;
  128.       var _loc9_ = 0;
  129.       if(this.__labelPlacement == "top")
  130.       {
  131.          _loc8_ = _loc22_ - _loc6_;
  132.       }
  133.       if(this.__label != undefined && this.__label != "")
  134.       {
  135.          this.labelPath._visible = false;
  136.          var _loc11_ = 1;
  137.          var _loc20_ = 1;
  138.          var _loc18_ = 5;
  139.          var _loc26_ = 4;
  140.          var _loc12_ = this.__value - this.__minimum;
  141.          if(_loc12_ < 0)
  142.          {
  143.             _loc12_ = 0;
  144.          }
  145.          var _loc13_ = this.__maximum - this.__minimum;
  146.          if(_loc13_ < 0)
  147.          {
  148.             _loc13_ = 0;
  149.          }
  150.          if(this.__labelPlacement == "left" || this.__labelPlacement == "right")
  151.          {
  152.             var _loc4_ = this.__label;
  153.             if(!this.__indeterminate)
  154.             {
  155.                _loc4_ = this.replace(_loc4_,"%1",String(Math.floor(_loc13_ / this.__conversion)));
  156.                _loc4_ = this.replace(_loc4_,"%2",String(Math.floor(_loc13_ / this.__conversion)));
  157.                _loc4_ = this.replace(_loc4_,"%3",String(100));
  158.                _loc4_ = this.replace(_loc4_,"%%","%");
  159.             }
  160.             else
  161.             {
  162.                _loc4_ = this.replace(_loc4_,"%1",String(Math.floor(_loc12_ / this.__conversion)));
  163.                _loc4_ = this.replace(_loc4_,"%2","??");
  164.                _loc4_ = this.replace(_loc4_,"%3","");
  165.                _loc4_ = this.replace(_loc4_,"%%","");
  166.             }
  167.             this.labelPath.text = _loc4_;
  168.             _loc7_ = _loc14_ - (this.labelPath.textWidth + _loc18_ + _loc11_);
  169.             if(_loc7_ < _loc5_ + _loc15_)
  170.             {
  171.                _loc7_ = 0;
  172.             }
  173.             if(this.__labelPlacement == "left")
  174.             {
  175.                _loc9_ = _loc14_ - _loc7_;
  176.             }
  177.          }
  178.          var _loc3_ = this.__label;
  179.          if(!this.__indeterminate)
  180.          {
  181.             _loc3_ = this.replace(_loc3_,"%1",String(Math.floor(_loc12_ / this.__conversion)));
  182.             _loc3_ = this.replace(_loc3_,"%2",String(Math.floor(_loc13_ / this.__conversion)));
  183.             _loc3_ = this.replace(_loc3_,"%3",String(Math.floor(this.percentComplete)));
  184.             _loc3_ = this.replace(_loc3_,"%%","%");
  185.          }
  186.          else
  187.          {
  188.             _loc3_ = this.replace(_loc3_,"%1",String(Math.floor(_loc12_ / this.__conversion)));
  189.             _loc3_ = this.replace(_loc3_,"%2","??");
  190.             _loc3_ = this.replace(_loc3_,"%3","");
  191.             _loc3_ = this.replace(_loc3_,"%%","");
  192.          }
  193.          this.labelPath.text = _loc3_;
  194.          var _loc10_ = 0;
  195.          if(this.__labelPlacement == "left" || this.__labelPlacement == "right")
  196.          {
  197.             _loc10_ = _loc14_ - _loc7_ - _loc11_;
  198.          }
  199.          else
  200.          {
  201.             _loc10_ = _loc14_ - _loc11_;
  202.          }
  203.          if(_loc10_ < this.labelPath.textWidth + _loc18_)
  204.          {
  205.             this.labelPath._width = _loc10_;
  206.          }
  207.          else
  208.          {
  209.             this.labelPath._width = this.labelPath.textWidth + _loc18_;
  210.          }
  211.          if(this.__labelPlacement == "left" || this.__labelPlacement == "right" || this.__labelPlacement == "center")
  212.          {
  213.             _loc10_ = _loc22_;
  214.          }
  215.          else
  216.          {
  217.             _loc10_ = _loc22_ - _loc20_ - _loc6_;
  218.          }
  219.          if(_loc10_ < this.labelPath.textHeight + _loc26_)
  220.          {
  221.             this.labelPath._height = _loc10_;
  222.          }
  223.          else
  224.          {
  225.             this.labelPath._height = this.labelPath.textHeight + _loc26_;
  226.          }
  227.          if(this.__labelPlacement == "left")
  228.          {
  229.             this.labelPath._x = _loc11_;
  230.          }
  231.          else if(this.__labelPlacement == "right")
  232.          {
  233.             this.labelPath._x = _loc7_ + _loc11_;
  234.          }
  235.          else
  236.          {
  237.             this.labelPath._x = _loc11_;
  238.          }
  239.          if(this.__labelPlacement == "center" || this.__labelPlacement == "left" || this.__labelPlacement == "right")
  240.          {
  241.             this.labelPath._y = _loc6_ / 2 - this.labelPath.height / 2;
  242.          }
  243.          else if(this.__labelPlacement == "top")
  244.          {
  245.             this.labelPath._y = _loc8_ - _loc20_ - this.labelPath.height;
  246.          }
  247.          else
  248.          {
  249.             this.labelPath._y = _loc6_ + _loc20_;
  250.          }
  251.          this.labelPath._visible = true;
  252.       }
  253.       else
  254.       {
  255.          this.labelPath.text = "";
  256.          this.labelPath._visible = false;
  257.       }
  258.       if(_loc7_ >= _loc5_ + _loc15_)
  259.       {
  260.          var _loc2_ = this.progTrackLeft_mc.getBounds(this.progTrackLeft_mc);
  261.          var _loc42_ = - _loc2_.xMin;
  262.          var _loc41_ = - _loc2_.yMin;
  263.          this.progTrackLeft_mc.move(_loc9_ + _loc5_ - this.progTrackLeft_mc._width + _loc42_,_loc8_ + (_loc6_ - this.progTrackLeft_mc._height) / 2 + _loc41_);
  264.          _loc2_ = this.progTrackMiddle_mc.getBounds(this.progTrackMiddle_mc);
  265.          var _loc38_ = - _loc2_.xMin;
  266.          var _loc35_ = - _loc2_.yMin;
  267.          this.progTrackMiddle_mc.setSize(_loc7_ - _loc5_ - _loc15_,this.progTrackMiddle_mc._height);
  268.          this.progTrackMiddle_mc.move(_loc9_ + _loc5_ + _loc38_,_loc8_ + (_loc6_ - this.progTrackLeft_mc._height) / 2 + _loc35_);
  269.          _loc2_ = this.progTrackRight_mc.getBounds(this.progTrackRight_mc);
  270.          var _loc31_ = - _loc2_.xMin;
  271.          var _loc32_ = - _loc2_.yMin;
  272.          this.progTrackRight_mc.move(_loc9_ + _loc5_ + this.progTrackMiddle_mc._width + _loc31_,_loc8_ + (_loc6_ - this.progTrackRight_mc._height) / 2 + _loc32_);
  273.          var _loc21_ = _loc7_ - _loc5_ - _loc15_;
  274.          var _loc16_ = _loc21_ * this.percentComplete / 100;
  275.          var _loc17_ = 0;
  276.          if(this.__indeterminate == true)
  277.          {
  278.             _loc16_ = _loc21_;
  279.             this.mask_mc._width = _loc16_;
  280.             this.mask_mc._height = this.progIndBar_mc._height;
  281.             this.mask_mc._x = _loc9_ + _loc5_;
  282.             this.mask_mc._y = _loc8_ + (_loc6_ - this.progIndBar_mc._height) / 2;
  283.             this.progIndBar_mc._width = _loc7_ * 200 / 150;
  284.             var _loc28_ = this.progIndBar_mc._x;
  285.             _loc2_ = this.progIndBar_mc.getBounds(this.progIndBar_mc);
  286.             ┬º┬ºpush(0);
  287.             ┬º┬ºpush(_loc2_.xMin);
  288.          }
  289.          else
  290.          {
  291.             this.progIndBar_mc._visible = false;
  292.             if(this.__direction == "left")
  293.             {
  294.                _loc17_ = _loc21_ - _loc16_;
  295.             }
  296.             _loc2_ = this.progBarMiddle_mc.getBounds(this.progBarMiddle_mc);
  297.             var _loc40_ = - _loc2_.xMin;
  298.             var _loc39_ = - _loc2_.yMin;
  299.             this.progBarMiddle_mc.setSize(_loc16_,this.progBarMiddle_mc._height);
  300.             this.progBarMiddle_mc.move(_loc17_ + _loc9_ + _loc5_ + _loc40_,_loc8_ + (_loc6_ - this.progBarLeft_mc._height) / 2 + _loc39_);
  301.             _loc2_ = this.progBarLeft_mc.getBounds(this.progBarLeft_mc);
  302.             var _loc36_ = - _loc2_.xMin;
  303.             var _loc33_ = - _loc2_.yMin;
  304.             this.progBarLeft_mc.move(_loc17_ + _loc9_ + _loc5_ - this.progBarLeft_mc._width + _loc36_,_loc8_ + (_loc6_ - this.progBarLeft_mc._height) / 2 + _loc33_);
  305.             _loc2_ = this.progBarRight_mc.getBounds(this.progBarRight_mc);
  306.             var _loc34_ = - _loc2_.xMin;
  307.             var _loc37_ = - _loc2_.yMin;
  308.             this.progBarRight_mc.move(_loc17_ + _loc9_ + _loc5_ + this.progBarMiddle_mc._width + _loc34_,_loc8_ + (_loc6_ - this.progBarRight_mc._height) / 2 + _loc37_);
  309.             this.progTrackLeft_mc._visible = true;
  310.             this.progTrackMiddle_mc._visible = true;
  311.             this.progTrackRight_mc._visible = true;
  312.             this.progBarLeft_mc._visible = true;
  313.             this.progBarMiddle_mc._visible = true;
  314.             this.progBarRight_mc._visible = true;
  315.          }
  316.       }
  317.       else
  318.       {
  319.          this.progTrackLeft_mc._visible = false;
  320.          this.progTrackMiddle_mc._visible = false;
  321.          this.progTrackRight_mc._visible = false;
  322.          this.progBarLeft_mc._visible = false;
  323.          this.progBarMiddle_mc._visible = false;
  324.          this.progBarRight_mc._visible = false;
  325.       }
  326.    }
  327.    function replace(str, from, to)
  328.    {
  329.       var _loc1_ = str.split(from);
  330.       var _loc2_ = _loc1_.join(to);
  331.       return _loc2_;
  332.    }
  333.    function getMode(Void)
  334.    {
  335.       return this.__mode;
  336.    }
  337.    function setMode(val)
  338.    {
  339.       if(val == "polled" || val == "manual")
  340.       {
  341.          this.__mode = val;
  342.       }
  343.       else
  344.       {
  345.          delete this.__mode;
  346.       }
  347.       this.invalidate();
  348.    }
  349.    function getDirection(Void)
  350.    {
  351.       return this.__direction;
  352.    }
  353.    function setDirection(val)
  354.    {
  355.       if(val == "left")
  356.       {
  357.          this.__direction = val;
  358.       }
  359.       else
  360.       {
  361.          delete this.__direction;
  362.       }
  363.       this.invalidate();
  364.    }
  365.    function getLabelPlacement(Void)
  366.    {
  367.       return this.__labelPlacement;
  368.    }
  369.    function setLabelPlacement(val)
  370.    {
  371.       if(val == "top" || val == "center" || val == "left" || val == "right")
  372.       {
  373.          this.__labelPlacement = val;
  374.       }
  375.       else
  376.       {
  377.          delete this.__labelPlacement;
  378.       }
  379.       this.invalidate();
  380.    }
  381.    function getIndeterminate(Void)
  382.    {
  383.       return this.__indeterminate;
  384.    }
  385.    function setIndeterminate(val)
  386.    {
  387.       if(val == true)
  388.       {
  389.          this.__indeterminate = true;
  390.       }
  391.       else
  392.       {
  393.          delete this.__indeterminate;
  394.       }
  395.       this.invalidate();
  396.    }
  397.    function getLabel(Void)
  398.    {
  399.       return this.__label;
  400.    }
  401.    function setLabel(val)
  402.    {
  403.       this.__label = val;
  404.       this.invalidate();
  405.    }
  406.    function getConversion(Void)
  407.    {
  408.       return this.__conversion;
  409.    }
  410.    function setConversion(val)
  411.    {
  412.       if(!_global.isNaN(val) && Number(val) > 0)
  413.       {
  414.          this.__conversion = Number(val);
  415.          this.invalidate();
  416.       }
  417.    }
  418.    function getSource(Void)
  419.    {
  420.       return this.__source;
  421.    }
  422.    function setSource(val)
  423.    {
  424.       if(typeof val == "string")
  425.       {
  426.          this.__stringSource = val;
  427.          val = eval(val);
  428.       }
  429.       if(val != null && val != undefined && val != "")
  430.       {
  431.          this.__source = val;
  432.          if(this.__mode == "event")
  433.          {
  434.             if(this.__source.addEventListener)
  435.             {
  436.                this.__source.addEventListener("progress",this);
  437.                this.__source.addEventListener("complete",this);
  438.             }
  439.             else
  440.             {
  441.                this.__source = undefined;
  442.             }
  443.          }
  444.          if(this.__mode == "polled")
  445.          {
  446.             this.si = setInterval(this,"update",this.__interval);
  447.          }
  448.       }
  449.       else if(this.__source != null)
  450.       {
  451.          delete this.__source;
  452.          clearInterval(this.si);
  453.          delete this.si;
  454.       }
  455.    }
  456.    function update(Void)
  457.    {
  458.       var _loc2_ = this.__source;
  459.       var _loc3_ = _loc2_.getBytesLoaded();
  460.       var _loc4_ = _loc2_.getBytesTotal();
  461.       this._setProgress(_loc3_,_loc4_);
  462.       if(this.percentComplete >= 100 && this.__value > 0)
  463.       {
  464.          clearInterval(this.si);
  465.       }
  466.    }
  467.    function progress(pEvent)
  468.    {
  469.       var _loc2_ = pEvent.target;
  470.       var _loc3_ = _loc2_.bytesLoaded;
  471.       var _loc4_ = _loc2_.bytesTotal;
  472.       this._setProgress(_loc3_,_loc4_);
  473.    }
  474.    function complete(pEvent)
  475.    {
  476.    }
  477.    function _setProgress(completed, total)
  478.    {
  479.       if(!_global.isNaN(completed) && !_global.isNaN(total))
  480.       {
  481.          this.__value = Number(completed);
  482.          this.__maximum = Number(total);
  483.          if(this.__mode != "event")
  484.          {
  485.             this.dispatchEvent({type:"progress",current:completed,total:total});
  486.             if(this.__value == this.__maximum && this.__value > 0)
  487.             {
  488.                this.dispatchEvent({type:"complete",current:completed,total:total});
  489.             }
  490.          }
  491.          this.invalidate();
  492.       }
  493.    }
  494.    function setProgress(completed, total)
  495.    {
  496.       if(this.__mode == "manual")
  497.       {
  498.          this._setProgress(completed,total);
  499.       }
  500.    }
  501.    function getPercentComplete(Void)
  502.    {
  503.       if(this.__value < this.__minimum || this.__maximum < this.__minimum)
  504.       {
  505.          return 0;
  506.       }
  507.       var _loc3_ = 100 * (this.__value - this.__minimum) / (this.__maximum - this.__minimum);
  508.       if(_global.isNaN(_loc3_) || _loc3_ < 0)
  509.       {
  510.          return 0;
  511.       }
  512.       if(_loc3_ > 100)
  513.       {
  514.          return 100;
  515.       }
  516.       return _loc3_;
  517.    }
  518.    function getMaximum(Void)
  519.    {
  520.       return this.__maximum;
  521.    }
  522.    function setMaximum(val)
  523.    {
  524.       if(!_global.isNaN(val) && this.__mode == "manual")
  525.       {
  526.          this.__maximum = Number(val);
  527.          this.invalidate();
  528.       }
  529.    }
  530.    function getMinimum(Void)
  531.    {
  532.       return this.__minimum;
  533.    }
  534.    function setMinimum(val)
  535.    {
  536.       if(!_global.isNaN(val) && this.__mode == "manual")
  537.       {
  538.          this.__minimum = Number(val);
  539.          this.invalidate();
  540.       }
  541.    }
  542.    function getVal(Void)
  543.    {
  544.       return this.__value;
  545.    }
  546.    function get mode()
  547.    {
  548.       return this.getMode();
  549.    }
  550.    function set mode(x)
  551.    {
  552.       this.setMode(x);
  553.    }
  554.    function get source()
  555.    {
  556.       return this.getSource();
  557.    }
  558.    function set source(x)
  559.    {
  560.       this.setSource(x);
  561.    }
  562.    function get direction()
  563.    {
  564.       return this.getDirection();
  565.    }
  566.    function set direction(x)
  567.    {
  568.       this.setDirection(x);
  569.    }
  570.    function get label()
  571.    {
  572.       return this.getLabel();
  573.    }
  574.    function set label(x)
  575.    {
  576.       this.setLabel(x);
  577.    }
  578.    function get labelPlacement()
  579.    {
  580.       return this.getLabelPlacement();
  581.    }
  582.    function set labelPlacement(x)
  583.    {
  584.       this.setLabelPlacement(x);
  585.    }
  586.    function get indeterminate()
  587.    {
  588.       return this.getIndeterminate();
  589.    }
  590.    function set indeterminate(x)
  591.    {
  592.       this.setIndeterminate(x);
  593.    }
  594.    function get conversion()
  595.    {
  596.       return this.getConversion();
  597.    }
  598.    function set conversion(x)
  599.    {
  600.       this.setConversion(x);
  601.    }
  602.    function get percentComplete()
  603.    {
  604.       return this.getPercentComplete();
  605.    }
  606.    function get maximum()
  607.    {
  608.       return this.getMaximum();
  609.    }
  610.    function set maximum(x)
  611.    {
  612.       this.setMaximum(x);
  613.    }
  614.    function get minimum()
  615.    {
  616.       return this.getMinimum();
  617.    }
  618.    function set minimum(x)
  619.    {
  620.       this.setMinimum(x);
  621.    }
  622.    function get value()
  623.    {
  624.       return this.getVal();
  625.    }
  626. }
  627.